<template>
  <VPage>
    <VTable ref="tableRef" v-bind="tableOptions">
      <template #form="{ form }">
        <el-input v-model="form.bank_name" class="w-40" placeholder="银行名称"></el-input>
        <VSelect v-model="form.bank_type" placeholder="银行类型" :options="options.bank_type" multiple collapse-tags filterable clearable style="min-width: 160px" />
        <VCascader v-model="form.update_user_id" placeholder="更新人" multiple collapse-tags filterable clearable style="min-width: 160px" />
        <VGroup>
          <div class="v-group-item">更新时间</div>
          <VDate v-model="form.dateRange.value" />
        </VGroup>
      </template>
      <template #toolbar_btns>
        <VButton auth="/purchase/supplier/bank/add" type="primary" @click="create(tableRef)"><i class="dk-iconfont icon-Plus" />添加</VButton>
        <VExport auth="/purchase/supplier/bank/derive" mainKey="sb_id" url="/v1/supplier/supplier-bank/export" :name="baseName" :tableRef="tableRef" class="ml-auto" />
      </template>
    </VTable>
    <Add ref="addRef" :options="options" @success="query" />
    <VLog ref="logRef" />
  </VPage>
</template>
  
<script setup lang="jsx" name="Account">
import api from './api'
import Add from './components/Add.vue'
import { getOption } from '@/api/public'

const route = useRoute()
console.log('route', route)

const baseName = 'supplier_bank'
const tableRef = ref()
const logRef = ref()
const loadings = reactive({})
// 查询
const query = () => {
  tableRef?.value.query()
}

// 新增
const addRef = ref()
const create = () => {
  addRef?.value.open()
}

// 获取options
const options = ref({})
getOption({ type: baseName }).then(res => {
  options.value = res.data
})

// 列表配置
const tableOptions = reactive({
  formConfig: {
    data: {
      bank_name: '',
      bank_type: [],
      update_user_id: [],
      dateRange: { type: 'update_time', value: [], range: true },
    }
  },
  columns: [
    { type: 'seq', title: '编号', fixed: 'left', width: 60 },
    {
      field: 'bank_name', title: '银行名称', minWidth: 200, slots: {
        default: ({ row }) => <VText value={row.bank_name} />
      }
    },
    {
      field: 'bank_type_name', title: '银行类型', minWidth: 100, slots: {
        default: ({ row }) => <VText value={row.bank_type_name} />
      }
    },
    {
      field: 'update_user', title: '更新人', minWidth: 100, slots: {
        default: ({ row }) => <VText value={row.update_user} />
      }
    },
    {
      field: 'update_time', title: '更新时间', minWidth: 150, slots: {
        default: ({ row }) => <VText value={row.update_time} />
      }
    },
    {
      title: '操作', width: 170, fixed: 'right', slots: {
        default: ({ row }) => {
          const { sb_id } = row
          return [<div>
            <VButton auth="/purchase/supplier/bank/edit" link type="primary" onClick={() => addRef?.value.open(sb_id)}>编辑</VButton>
            <VButton auth="/purchase/supplier/bank/logs" link type="primary" onClick={() => logRef?.value.open({ log_type: baseName, sb_id })}>日志</VButton>
          </div>]
        }
      }
    },
  ],
  proxyConfig: {
    autoLoad: false,
    ajax: {
      query: ({ page, form }) => api.query({ ...form, ...page })
    }
  }
})
</script>
  